package com.ryan.plugin.output;

import com.google.gson.Gson;
import com.ryan.plugin.store.AClass;
import com.ryan.plugin.store.Store;

import java.util.HashMap;

public class JSON {
    public static String toJson(Store store) {
        HashMap<AClass, HashMap<String, String>> data = store.getData();
        HashMap<AClass, HashMap<String, String>> exceptions = store.getExceptions();

        Output output = new Output();
        data.forEach((aClass, map) -> {
            OutputClass o = OutputClass.from(aClass);
            if (map != null) {
                map.forEach((m, tag) -> o.methods.add(new OutputMethod(m, tag)));
            }
            output.data.add(o);
        });

        exceptions.forEach((aClass, map) -> {
            OutputClass o = OutputClass.from(aClass);
            if (map != null) {
                map.forEach((m, tag) -> o.methods.add(new OutputMethod(m, tag)));
            }
            output.exceptions.add(o);
        });
        return new Gson().toJson(output);
    }
}
